package com.ibeeking.found.cop.b.rest.controller.v1;

import com.ibeeking.found.cop.b.rest.service.ICopSensitiveWordService;
import com.ibeeking.found.cop.service.common.enums.MqSyncOperatorTypeEnum;
import com.ibeeking.found.cop.service.common.param.CopSensitiveWordParam;

import com.ibeeking.found.cop.service.common.query.CopSensitiveWordQuery;
import com.ibeeking.found.cop.service.common.vo.CopSensitiveWordVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.base.BaseValidationGroup;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName CopSensitiveWordController
 * @Description
 * @Author ibeeking
 * @Date 2021-06-02 18:15
 **/
@RestController
@RequestMapping("/b/sensitiveWord/v1")
public class CopSensitiveWordController {

    @Resource
    private ICopSensitiveWordService CopSensitiveWordServiceImpl;

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询敏感词列表")
    @PostMapping(value = "/list")
    public List<CopSensitiveWordVO> list(@RequestBody CopSensitiveWordQuery query) {
        return CopSensitiveWordServiceImpl.list(query);
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "添加敏感词")
    @PostMapping(value = "/add")
    public Boolean add(@RequestBody @Validated(BaseValidationGroup.Insert.class) CopSensitiveWordParam param) {
        return CopSensitiveWordServiceImpl.add(param);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "修改敏感词")
    @PostMapping(value = "/modify")
    public Boolean modify(@RequestBody @Validated(BaseValidationGroup.Update.class) CopSensitiveWordParam param) {
        return CopSensitiveWordServiceImpl.modify(param);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "修改是否启用")
    @GetMapping(value = "/changeStatus/{id}/{status}")
    public Boolean changeStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        return CopSensitiveWordServiceImpl.changeStatus(id, status);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查看敏感词详情")
    @GetMapping(value = "/view/{id}")
    public CopSensitiveWordVO view(@PathVariable("id") Long id) {
        return CopSensitiveWordServiceImpl.view(id);
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "删除敏感词")
    @GetMapping(value = "/del/{id}")
    public Boolean del(@PathVariable("id") Long id) {
        return CopSensitiveWordServiceImpl.del(id);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "从企业微信同步敏感词")
    @PostMapping(value = "/syncSensitiveWordToWxCp/{id}")
    public Integer syncSensitiveWordToWxCp(@PathVariable("id") Long id) {
        return CopSensitiveWordServiceImpl.sendInstructionToMq(id, MqSyncOperatorTypeEnum.COP_SYNC_SENSITIVE_WORD_EDIT.getCode());
    }

}
